package pers.qianyu.month_202012.date_20201210;

import org.junit.*;

import java.util.*;

/**
 * [同 date_20201112]
 * 46. 全排列
 * https://leetcode-cn.com/problems/permutations/
 *
 * @author mizzle rain
 * @date 2020-12-10 15:11
 */
public class Permute {
    ArrayList<List<Integer>> res = new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        ArrayList<Integer> track = new ArrayList<>();
        recur(track, nums);
        return res;
    }

    private void recur(List<Integer> track, int[] nums) {
        if (track.size() == nums.length) {
            res.add(new ArrayList<>(track));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (track.contains(nums[i])) {
                continue;
            }
            track.add(nums[i]);
            recur(track, nums);
            track.remove(track.size() - 1);
        }
    }

    @Test
    public void test1() {
        int[] param = {1, 2, 3};
        List<List<Integer>> result = new Permute().permute(param);
        System.out.println("result = " + result);
    }
}
